package com.bbh.plugin.single.privilege.core.service;


import com.bbh.plugin.single.privilege.core.entity.Rule;
import com.bbh.plugin.single.privilege.core.repository.RuleMapper;
import com.bbh.plugin.single.privilege.core.vo.tree.RuleVo;
import com.bbh.common.domain.Condition;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import com.bbh.common.domain.Page;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import com.bbh.common.base.service.BaseService;
@Service
@Transactional
public class RuleService extends BaseService<Rule, String> {
    @Autowired
    private RuleMapper ruleMapper;
    @Autowired
    private RoleRuleService roleRuleService;
    @Autowired
    private RoleService roleService;

    /**
     * 查询用户角色列表
     *
     * @return
     */
    public Page<RuleVo> findRoleRuleList(Map<String, Object> params, Page pageable) {
        PageHelper.startPage(pageable.getPageNum() + 1, pageable.getPageSize());
        List<RuleVo> roleVoList = ruleMapper.findRoleRuleList(params);
        PageInfo<RuleVo> pageInfo = new PageInfo<RuleVo>(roleVoList);
        return pageConverter(pageInfo);
    }

    /**
     * 通过loginName获取rule
     *
     * @param loginName
     * @return
     */
    public List<Rule> findRuleListByLoginName(String appKey, String loginName) {
            Condition condition = new Condition(true);
            condition.put("appKey", appKey);
            condition.put("loginName", loginName);
            List<Rule> ruleList= ruleMapper.findRuleListByLoginName(condition);
            return ruleList;
    }

}
